/*
  This file is part of JCM.

  JCM is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  JCM is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with JCM.  If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * Diálogo personalizado para uso desse aplicativo.
*/
public class AboutDialog extends JDialog implements ActionListener
{
  /**
   * Construtor do objeto.
   *
   * @param owner O frame proprietário desse diálogo.
   * @param msg Texto com a versão do aplicativo.
  */
  public AboutDialog(Frame owner, String msg)
  {
    super(owner, "About", true);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    setResizable(false);

    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout(0, 3));
    pane.setBorder(new EmptyBorder(10, 20, 10, 20));

    JLabel label = new JLabel(
      new ImageIcon(
        this.getClass().getClassLoader().getResource("images/jcm.gif")),
      JLabel.CENTER);
    pane.add(label, BorderLayout.NORTH);

    label = new JLabel("<html>" + msg + "</html>", JLabel.CENTER);
    pane.add(label, BorderLayout.CENTER);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BorderLayout(0, 5));
    pane.add(buttonPane, BorderLayout.SOUTH);

    label = new JLabel(
      "<html><p style='font:400 9px sans-serif'>Copyright &copy; 2008-2011 Antonio S. Ando</p></html>",
      JLabel.CENTER);
    buttonPane.add(label, BorderLayout.NORTH);

    label = new JLabel(
      new ImageIcon(
        this.getClass().getClassLoader().getResource("images/kanji.png")),
      JLabel.CENTER);
    buttonPane.add(label, BorderLayout.CENTER);

    JButton okBtn = new JButton("Ok");
    okBtn.setPreferredSize(new Dimension(80, 30));
    okBtn.setMnemonic(KeyEvent.VK_K);
    okBtn.setFont(new Font(Font.DIALOG, Font.BOLD, 13));
    okBtn.addActionListener(this);

    JPanel butPane = new JPanel();
    butPane.add(okBtn);
    buttonPane.add(butPane, BorderLayout.SOUTH);

    this.setContentPane(pane);
  }

  /**
   * Cria um componente JRootPane associando a tecla Escape a ação de
   * fechar essa janela de diálogo.
   *
   * @return Instância de componente JRootPane especializada.
  */
  @Override protected JRootPane createRootPane()
  {
    JRootPane root = new JRootPane();
    String actionName = "ESCAPE";
    Action action = new AbstractAction()
    {
      public void actionPerformed(ActionEvent ae) { setVisible(false); }
      private static final long serialVersionUID = -7727201964869006422L;
    };
    InputMap inputMap = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(actionName), actionName);
    root.getActionMap().put(actionName, action);

    return root;
  }

  public void actionPerformed(ActionEvent e)
  {
    setVisible(false);
  }

  private final static long serialVersionUID = 8079344512052286441L;
}